from collections import deque


def shortest_path(maze):
    rows = len(maze)
    cols = len(maze[0])
    directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]
    start = (0, 0)
    end = (rows - 1, cols - 1)
    queue = deque([(start, 0)])
    visited = set()
    visited.add(start)
    while queue:
        (x, y), steps = queue.popleft()
        if (x, y) == end:
            return steps
        for direction in directions:
            new_x = x + direction[0]
            new_y = y + direction[1]
            if 0 <= new_x < rows and 0 <= new_y < cols and maze[new_x][new_y] == 0 and (new_x, new_y) not in visited:
                queue.append(((new_x, new_y), steps + 1))
                visited.add((new_x, new_y))
    return -1

maze = [
    [0, 1, 0, 0],
    [0, 0, 1, 0],
    [0, 0, 0, 0]
]
print(shortest_path(maze))
